package com.pubinfo.passbook.common.model.bo.witeoff;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.pubinfo.passbook.common.entity.TMdmSupplier;
import com.pubinfo.passbook.common.entity.TWiteoffInvoiceInfo;
import com.pubinfo.passbook.common.entity.TWiteoffRelateSupplier;
import com.pubinfo.passbook.common.model.ruler.UserAcc;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(value = "EnvironmentalOrGroupMembershipDuesDTO", description = " (环保费|社会团体费)报账,接收前端报账单数据")
public class EnvironmentalOrGroupMembershipDuesDTO extends WiteoffBase {
  
  @ApiModelProperty(value = "关联发票id集合")
  List<String> invoiceIds;
//  
//  @JacksonXmlElementWrapper(localName = "lineItems")
//  @JacksonXmlProperty(localName = "lineItem")
//  public List<EnvironmentalOrGroupMembershipDuesSubitem> getLineItems() {
//    return lineItems;
//  }
  
  @JacksonXmlElementWrapper(localName = "invoiceIds")
  @JacksonXmlProperty(localName = "invoiceId")
  public List<String> getInvoiceIds() {
    return invoiceIds;
  }
  
  /**
   * 此构造方法走发票报账.
   *
   * @param invoiceInfos  报账发票信息
   * @param type          类型 如果type为0 则为环保费,为1,则为社会团体费
   * @param supplier      供应商信息，默认只有一个
   * @param sapCompayCode 公司代码
   * @param supplierBank  供应商银行信息
   * @param userAcc       报账人信息
   */
  public EnvironmentalOrGroupMembershipDuesDTO(List<TWiteoffInvoiceInfo> invoiceInfos, Integer type, TMdmSupplier supplier, String sapCompayCode, UserAcc userAcc) {
    //需要问的sapCompayCode
    //如果type为0 则为环保费,为1,则为社会团体费
    //默认金额小于50000,如果大于50000走人工
    if (type == 0) {
      this.desc = "报XXX污水处理费";
    } else if (type == 1) {
      this.desc = "报XXX团体会费";
    }
    this.account = userAcc.getAccount();
    this.fillInName = userAcc.getName();
    this.fillInOrgCode = userAcc.getOrgCode();
    // account  fillInName  fillInOrgCode sapCompayCode
    this.economicItemCode = "10040404"; //电子发票走那个?
    this.economicItemName = "行政事业社团收费";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    this.happenDate = dateFormat.format(new Date());
    this.budgetSet = new SimpleDateFormat("yyyy-MM").format(new Date());
    this.accountCode = "1002B88P00";
    this.accountName = "省公司财务公司综合户01001";
    this.isStaffPayment = 1;
    this.sapCompayCode = sapCompayCode;
    //contractNo  contractName 票据金额小于5万的报账时合同都不填、如果大于等于5万转人工报账
    BigDecimal sum = new BigDecimal(0);
    if (!CollectionUtils.isEmpty(invoiceInfos)) {
      for (TWiteoffInvoiceInfo invoiceInfo : invoiceInfos) {
        sum = sum.add(new BigDecimal(invoiceInfo.getSum()));
      }
    }
    this.sum = sum;
  
    this.invoiceType = 12; //12-电子发票-普票
    //delegationBankCode  委托划扣银行账号不是必填，这个一般是收支方式为已支付的才要填
    //供应商不用
    //relateSuppliers ? payMentItems
    this.invoiceInfos = invoiceInfos;
//    EnvironmentalOrGroupMembershipDuesSubitem subitem = new EnvironmentalOrGroupMembershipDuesSubitem(sum, type, sapCompayCode);
//    lineItems.add(subitem);
  
    //供应商
    List<TWiteoffRelateSupplier> relateSuppliers = new ArrayList<>();
    TWiteoffRelateSupplier relateSupplier = new TWiteoffRelateSupplier(supplier, sum.doubleValue());
    relateSuppliers.add(relateSupplier);
    this.relateSuppliers = relateSuppliers;
  
    //收款方
//    List<TWiteoffPayMent> payMents = new ArrayList<>();
//    TWiteoffPayMent bank = new TWiteoffPayMent(supplierBank, sum);
//    payMents.add(bank);
    //  this.payMentItems = payMents;
  }
}
